package com.itcast.dao;

import com.itcast.domain.Shopping_Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.TreeSet;

@Repository
public interface Shopping_OrderDao {
    /**
     * 结算商品，形成订单
     * @param order
     * @return
     */
    @Insert("<script>" +
                " insert into shopping_order(name,number,price,time) values " +
                "<foreach collection='list' item='item' index='index' separator=','>" +
                    "(#{item.name},#{item.number},#{item.price},#{item.time})" +
                "</foreach>" +
            "</script>"
    )
    int settle(List<Shopping_Order> order);

    @Select("select * from shopping_order")
    List<Shopping_Order> findAll();

    @Delete("delete from shopping_order where time = #{time}")
    int  byTimeDelete(Date time);

    @Select("select time from shopping_order")
    TreeSet<Date> findTime();

    @Select("select * from shopping_order where time = #{time}")
    List<Shopping_Order> byTimeFind(Date time);
}
